// Please install OpenAI SDK first: `npm install openai`

import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: "4194ee491549fc905221899dec6b082350e71144",
  // baseURL: "https://api-j8ybkcz7bei62ez1.aistudio-app.com/v1"
  baseURL: "https://api-k9a6abl6s8v7a4pd.aistudio-app.com/v1"
});

async function main() {
  const completion = await openai.chat.completions.create({
    // messages: [{ "role": "user", "content": "写一个快速排序算法" }],
    messages: [{ "role": "user", "content": "js语法中，cjs 和 esm 的区别" }],
    // messages: [{ "role": "user", "content": `js 优雅的判断对象的是否为空对象` }],
    model: "deepseek-r1:1.5b",
    stream: true,
    temperature: 0.6,
  });
    
  for await (const chunk of completion) {
    if (chunk.choices[0].delta.content) {
      process.stdout.write(chunk.choices[0].delta.content);
    }
  }
}

main();